<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="org.jeecgframework.web.util.StaticValue" %>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>返件详情页</title>
    <t:base type="jquery,easyui,tools,DatePicker"></t:base>
    <script type="text/javascript" src="plug-in/ckfinder/ckfinder.js"></script>
    <link rel="stylesheet" href="plug-in/uploadify/css/uploadify.css" type="text/css"/>
    <script type="text/javascript" src="plug-in/uploadify/jquery.uploadify-3.1.min.js"></script>
    <script type="text/javascript" src="plug-in/jquery/ajaxfileupload.js"></script>
    <script type="text/javascript" src="plug-in/jquery/jquerysession.js"></script>
    <script type="text/javascript">
        //编写自定义JS代码
        $(document).ready(function () {
            getContacts();
        })

        function getCity() {
            var shengId=$('#sheng').val();
            $.ajax({
                type: "post",
                data: {"id": shengId},
                url: "cbsReturnEquipmentController.do?getCity",
                dataType: "json",
                success: function (data) {
                    var tbs = data.obj;
                    var html = "<option value=''>--请选择城市--</option>";
                    for (i in tbs) {
                        html += '<option  value=' + tbs[i].id + '>' + tbs[i].territoryName + '</option>';
                    }
                    $("#shi").html(html);

                }
            })
        }
        function hideErr() {
            var shi=$('#shi').val()
            if(shi!=null && shi!=''){
                $('#shiErr').hide()
            }
        }
        function lookImg(id) {
                    addOneTab('预览','cbsServiceController.do?openViewFile&fileid='+id)
        }

        function lookBackImg(id) {
            //alert(id)
            $.ajax({
                url : "cbsReturnEquipmentController.do?getBackImgFile",
                data : {"businessKey" : id},
                cache : false,
                dataType : 'json',
                type : 'POST',
                async : false,
                success : function(data){
                    var tbs=data.obj;
                    console.log("tbs:"+tbs[0])
                    addOneTab('预览','cbsServiceController.do?openViewFile&fileid='+tbs[0])
                }
            });
        }
    </script>
    <style type="text/css">
        .noSelect {
            border: 0;
            /*display: block;*/
            /*position: relative;*/
            min-height: 1.146667rem;
            line-height: 1.146667rem;
            white-space: nowrap;
            /*width: 100%;*/
            overflow: hidden;
            padding-right: .6rem;
            background-color: #eee;
            background: transparent;
            appearance: none;
            -moz-appearance: none; /* Firefox */
            -webkit-appearance: none; /* Safari 和 Chrome */
        }
    </style>
</head>
<body>
<div style="margin-bottom:10px;">
    <img style="margin-bottom:-7px" src="plug-in/login/images/dispatch bill.png">
    <span class="list-title" id="reTurnCode">${cbsReturnEquipmentPage.code}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <span style="font-size:13px;">状态：<span style="color: red" >${status}
        <%--<t:dictSelect field="status" id="status" clazz="noSelect" readonly="true"
                      typeGroupCode="<%=StaticValue.RETURN_STATUS_Log_Type%>"
                      defaultVal="${status}">
        </t:dictSelect>--%>
    </span></span>
    <input id="status" hidden="hidden" value="${cbsReturnEquipmentPage.status}">
    <div style="position: absolute; text-align: center; width: 100%; margin-top:-20px;">
        <a href="#" class="easyui-linkbutton l-btn" onclick="preservation('${cbsReturnEquipmentPage.id}')">保存</a>
        <a href="#" class="easyui-linkbutton l-btn" onclick="cancelTheShipment('${cbsReturnEquipmentPage.id}')">取消返件</a>
    </div>
</div>
<div class="subtitle">
    <input id="returnId" hidden="hidden" value="${cbsReturnEquipmentPage.id}">
    <p>关联信息</p>
    <table class="nobordertable noborder">
        <tbody>
        <tr>
            <td class="al_r" width="20%">
                <label>服务单号CR:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.crCode}
            </td>
            <td class="al_r" width="20%">
                <label>备件申请单号:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.equipmentApplyId.recordId}
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>发货单号:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.deliverCode}
            </td>
            <td class="al_r" width="20%">
                <label>SR:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.srCode}
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>SO:</label>
            </td>
            <td width="30%">
                ${cbsReturnEquipmentPage.soCode}
            </td>
            <td class="al_r" width="20%">

            </td>
            <td width="30%">

            </td>
        </tr>
        </tbody>
    </table>
</div>

<c:if test="${not empty cbsReturnEquipmentDetailEntities}">
<div class="subtitle">
    <p>返件信息</p>
    </c:if>
    <c:forEach items="${cbsReturnEquipmentDetailEntities}" var="r" varStatus="i">
        <input type="hidden" name="index" id="index" value="${i.index}">
        <input type="hidden" name="rd_${i.index}" id="rd_${i.index}" value="${r.id}">
        <div style="margin-top:20px; width: 98%; margin: 0px auto;"><span
                style="font-weight: bold;">返件：${i.index+1}</span></div>
        <div class="l-div">
            <table class="nobordertable noborder" style="border: none;">
                <tbody>
                <tr>
                    <td class="al_r" width="20%">
                        <label>类型:<font color="red">*</font></label>
                    </td>
                    <td width="30%">
                        <input name="equipmentTypeId" class="typeDescId" id="${r.id}"  type="hidden"  value="${r.typeId.id}"/>
                        <input class="inputxt" name="equipmentType" readonly="readonly" uuid="*" type="text" id="${r.id}typeDes" value="${r.typeDes}" onchange="checkeNull(this)"/>
                        <input class="button" value="选择" type="button" id="${r.typeId.id}" onclick="getTree(this,'${r.id}')"/>
                        <span id="${r.id}typeDesErr" hidden="hidden" style="font-size: 10px;color: red">类型不能为空</span>
                    </td>
                    <td class="al_r" width="20%">
                        <label>备件号:<font color="red">*</font></label>
                    </td>
                    <td width="30%">
                        <c:if test="${not empty r.itemId}">
                            <input type="text" hidden="hidden"  <c:if test="${r.itemId.isTrack=='1'}">value="is"</c:if> class="equipmentCode" id="${r.id}isTrack">
                            <input type="text" onkeyup="hideErr('${r.id}itemId',this)"  hidden="hidden" class="equipmentCode" id="${r.id}in" value="${r.item}" >
                            <select name="equipmentItem" id="${r.id}itemId" onchange="checkeNull(this);getIsTrack('${r.id}');getItem('${r.id}')">
                                <option value="">--请选择备件号--</option>
                                <c:forEach items="${equipmentItemMap[r.id]}" var="item">
                                    <c:if test="${item.id==r.itemId.id}">
                                        <option value="${item.id}" selected="selected">${item.item}</option>
                                    </c:if>
                                    <c:if test="${item.item!=r.item}">
                                        <option value="${item.id}">${item.item}</option>
                                    </c:if>
                                </c:forEach>
                                    <%--<option value="${deliverEquipment.item.id}" selected="selected">${deliverEquipment.item.item}</option>--%>
                            </select>
                        </c:if>
                        <c:if test="${empty r.itemId}">
                            <input type="text" hidden="hidden"   class="equipmentCode" id="${r.id}isTrack">
                            <input type="text"  onkeyup="hideErr('${r.id}itemId',this)"  class="equipmentCode" id="${r.id}in" value="${r.item}">
                            <select hidden="hidden" name="equipmentItem" id="${r.id}itemId" onchange="checkeNull(this);getIsTrack('${r.id}');getItem('${r.id}')">
                                <option value="">--请选择备件号--</option>
                                <c:forEach items="${equipmentItemMap[r.id]}" var="item">
                                    <option value="${item.id}">${item.item}</option>
                                </c:forEach>
                                    <%--<option value="${deliverEquipment.item.id}" selected="selected">${deliverEquipment.item.item}</option>--%>
                            </select>
                        </c:if>
                        <span id="${r.id}itemIdErr"  hidden="hidden" style="font-size: 10px;color: red">备件号不能为空</span>
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%">
                        <label>状态:<font color="red">*</font></label>
                    </td>
                    <td width="30%">
                        <select id="returnEquipmentStatus_${i.index}" id="returnEquipmentStatus_${i.index}" onchange="checkeNull(this)">
                            <option value="">--请选择返件状态--</option>
                            <option value="1" <c:if test="${r.returnEquipmentStatus==1}">selected="selected"</c:if> >DOA</option>
                            <option value="2" <c:if test="${r.returnEquipmentStatus==2}">selected="selected"</c:if>>好件</option>
                            <option value="3" <c:if test="${r.returnEquipmentStatus==3}">selected="selected"</c:if>>坏件</option>
                        </select>
                        <span id="returnEquipmentStatus_${i.index}Err" hidden="hidden"  style="font-size: 10px;color: red">返件状态不能为空</span>
                    </td>
                    <td class="al_r" width="20%">
                        <label>序列号:<font class="${r.id}isTrack" <c:if test="${r.itemId.isTrack!='1'}">hidden="hidden"</c:if>  color="red">*</font></label>
                    </td>
                    <td width="30%">
                        <input onkeyup="hideErr('sn${r.id}',this)"  name="sn_${i.index}" id="sn_${i.index}" value="${r.sn}"/><span id="sn${r.id}Err" hidden="hidden"  style="font-size: 10px;color: red">序列号不能为空</span>
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%" valign="top">
                        <label>备件照片:<font class="${r.id}isTrack" <c:if test="${r.itemId.isTrack!='1'}">hidden="hidden"</c:if>  color="red" >*</font></label>
                    </td>
                    <td width="30%">
                        <input type="button" id="photoNames_${i.index}" value="上传附件"/><span id="photo${i.index}Err" hidden="hidden"  style="font-size: 10px;color: red">备件照片不能为空</span>
                    </td>
                    <td class="al_r" width="20%" valign="top">
                        <label>二维码:<font class="${r.id}isTrack" <c:if test="${r.itemId.isTrack!='1'}">hidden="hidden"</c:if>  color="red">*</font></label>
                    </td>
                    <td width="30%" valign="top">
                        <input onkeyup="hideErr('equipmentErcode${r.id}',this)"  id="equipmentErcode_${i.index}" name="equipmentErcode_${i.index}" value="${r.equipmentErcode}"><span id="equipmentErcode${r.id}Err" hidden="hidden"  style="font-size: 10px;color: red">二维码不能为空</span>
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%" valign="top">
                    </td>
                    <td colspan="3">
                            <%-- <input type="text" hidden value="${r.photoName}" id="photoName_${i.index}" name="photoName_${i.index}"/>--%>
                        <span class="fileId_${i.index}" id="fileId_${i.index}" style="width: 120px;">
                             <c:forEach items="${detailFileList}" var="detailFile">
                                 <c:if test="${detailFile.businessChildType==r.id}">
                                     <%--<a  style="color: #0e90d2"  onclick="lookImg('${detailFile.id}')">${detailFile.oldFileName}</a>--%>
                                     <a style="color: blue" href="fileUploadController.do?downLoadFile&fileLogId=${detailFile.id}">${detailFile.oldFileName}</a>
                                     <span style="cursor: pointer;" onclick="delFile('${detailFile.id}')">删除</span>&emsp;
                                 </c:if>
                             </c:forEach>
                        </span>
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%" valign="top">
                        <label>备注:</label>
                    </td>
                    <td colspan="3">
                        <textarea style="width: 100%; height: 60px;" id="memo_${i.index}" name="memo_${i.index}" maxlength="255">${r.memo}</textarea>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </c:forEach>
    <c:if test="${not empty cbsReturnEquipmentDetailEntities}">
    <div style="text-align: center;" >
        <span <c:if test="${cbsReturnEquipmentPage.status!=1}"> hidden="hidden"</c:if>>
            <a href="#" class="easyui-linkbutton l-btn"
               onclick="notificationOfreturn('${cbsReturnEquipmentPage.id}')">通知返件</a>
        </span>
    </div>
</div>
</c:if>

<div class="subtitle">
    <p>取货联系人信息</p>
        <table class="nobordertable noborder" style="border: none;">
            <tbody>
            <tr>
                <td class="al_r" width="20%">
                    <label>姓名:<font class="qhContacts" color="red" hidden="hidden">*</font></label>
                </td>
                <td width="30%">
                    <input class="contactsClass"  name="name" id="name" value="${cbsReturnEquipmentPage.name}" onkeyup="hideErr('name',this)"><span id="nameErr" hidden="hidden"  style="font-size: 10px;color: red">取货联系人姓名不能为空</span>
                </td>
                <td class="al_r" width="20%">
                    <label>电话:<font class="qhContacts" color="red" hidden="hidden">*</font></label>
                </td>
                <td width="30%">
                    <input  class="contactsClass" name="phone" id="phone" value="${cbsReturnEquipmentPage.phone}" onkeyup="hideErr('phone',this)"><span id="phoneErr" hidden="hidden"  style="font-size: 10px;color: red">取货联系人电话不能为空</span>
                </td>
            </tr>
            <tr>
                <td class="al_r" width="20%">
                    <label>取货地址:<font class="qhContacts" color="red" hidden="hidden">*</font></label>
                </td>
                <td width="30%">
                    <select id="sheng" name="sheng" style="width: auto" onchange="getCity()">
                        <option value="">--请选择省份--</option>
                        <c:forEach items="${shengList}" var="sheng">
                            <option <c:if test="${sheng.id==cbsReturnEquipmentPage.sheng.id}">selected="selected"</c:if> value="${sheng.id}">${sheng.territoryName}</option>
                        </c:forEach>
                    </select>
                    <select id="shi" name="shi" style="width: auto" onchange="hideErr()">
                        <option value="">--请选择城市--</option>
                        <c:forEach items="${shiList}" var="shi" >
                            <option <c:if test="${shi.id==cbsReturnEquipmentPage.shi.id}">selected="selected"</c:if> value="${shi.id}">${shi.territoryName}</option>
                        </c:forEach>
                    </select>
                    <span hidden="hidden" id="shiErr" style="color: red">请选择省市</span>
                </td>
                <td class="al_r" width="20%">
                    <label>影院名称:</label>
                </td>
                <td width="30%">
                    <input  class="contactsClass" name="cinemaName" id="cinemaName" value="${cbsReturnEquipmentPage.cinemaName}">
                    <input type="hidden" id="sessionId" value="${pageContext.session.id}">
                </td>
            </tr>
            <tr>
                <td class="al_r" width="20%">
                </td>
                <td width="30%">
                    <input  class="contactsClass" name="address" style="width: 100%" id="address" value="${cbsReturnEquipmentPage.address}" onkeyup="hideErr('address',this)"><span id="addressErr" hidden="hidden"  style="font-size: 10px;color: red">取货地址不能为空</span>
                </td>
                <td class="al_r" width="20%">
                </td>
                <td width="30%">
                </td>
            </tr>
            </tbody>
        </table>
</div>
<div class="subtitle">
    <p>物流</p>
    <table class="nobordertable noborder" style="border: none;">
        <tbody>
        <tr>
            <td class="al_r" width="20%">
                <label>返件物流:</label>
            </td>
            <td width="30%">
                <select id="deliverLogistics" onchange="getContacts()">
                    <c:forEach items="${logisticsList}" var="logistics">
                        <option <c:if test="${logistics.departname==cbsReturnEquipmentPage.logistics}">selected="selected"</c:if> value="${logistics.departname}">${logistics.departname}</option>
                    </c:forEach>
                </select>
                <%--<input type="text" name="deliverLogistics" id="deliverLogistics" value="${tsDepart.shortname}">--%>
            </td>
            <td class="al_r" width="20%">
                <label>联系人:</label>
            </td>
            <td width="30%">
                <span id="userName"></span>
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>电话:</label>
            </td>
            <td width="30%">
                <span id="cellphone1"></span>
            </td>
            <td class="al_r" width="20%">
                <label>邮箱:</label>
            </td>
            <td width="30%">
                <span name="email" id="email"></span>
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>预计取货时间:</label>
            </td>
            <td width="30%">
                <span id="pickupTime" name="pickupTime">${cbsReturnEquipmentPage.pickupTime}</span>
            </td>
            <td class="al_r" width="20%">
                <label>预计回库时间:</label>
            </td>
            <td width="30%">
                <span id="backwarehouseTime" name="backwarehouseTime" >${cbsReturnEquipmentPage.backwarehouseTime}</span>
            </td>
        </tr>
        <tr>
            <td class="al_r" width="20%">
                <label>物流单号:</label>
            </td>
            <td width="30%">
                <span id="logisticsCode" name="logisticsCode">${cbsReturnEquipmentPage.logisticsCode}</span>
            </td>
            <td class="al_r" width="20%">
            </td>
            <td width="30%">
            </td>
        </tr>
        </tbody>
    </table>
</div>
<c:if test="${not empty cbsBackEquipmentDetailEntities}">
<div class="subtitle" hidden="hidden">
    <p>入库信息</p>
    </c:if>
    <c:forEach items="${cbsBackEquipmentDetailEntities}" var="b" varStatus="i">
        <div style="margin-top:20px; width: 98%; margin: 0px auto;">
            <span style="font-weight: bold;">返件：${i.index+1}</span>
        </div>
        <div class="l-div">
            <table class="nobordertable noborder" style="border: none;">
                <tbody>
                <tr>
                    <td class="al_r" width="20%">
                        <label>类型:</label>
                    </td>
                    <td width="30%">
                         ${b.returnEquipmentDetailId.typeId.typeDesc}
                    </td>
                    <td class="al_r" width="20%">
                        <label>备件号:</label>
                    </td>
                    <td width="30%">
                            ${b.sn}
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%">
                        <label>序列号:</label>
                    </td>
                    <td width="30%">
                            ${b.sn}
                    </td>
                    <td class="al_r" width="20%">
                        <label>物料号:</label>
                    </td>
                    <td width="30%">
                            ${b.verCode}
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%" valign="top">
                        <label>二维码:</label>
                    </td>
                    <td width="30%">
                            ${b.equipmentErcode}
                    </td>
                    <td class="al_r" width="20%" valign="top">
                        <label>版本号:</label>
                    </td>
                    <td width="30%">
                            ${b.verCode}
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%" valign="top">
                        <label>仓库:</label>
                    </td>
                    <td width="30%">
                            ${b.warehouseId.name}
                    </td>
                    <td class="al_r" width="20%" valign="top">
                        <label>库位:</label>
                    </td>
                    <td width="30%">
                            ${b.warehousePosition}
                    </td>
                </tr>
                <tr>
                    <td class="al_r" width="20%" valign="top">
                        <label>备注:</label>
                    </td>
                    <td width="30%">
                            ${b.memo}
                    </td>
                    <td class="al_r" width="20%" valign="top">
                        <label>备件照片:</label>
                    </td>
                    <td width="30%">
                        <c:forEach items="${backFileList}" var="backlFile">
                            <c:if test="${backlFile.businessChildType==b.id}">
                                <%--<a  style="color: #0e90d2"  onclick="lookImg('${backlFile.id}')">${backlFile.oldFileName}</a>--%>
                                <a style="color: blue;text-decoration: underline"  href="fileUploadController.do?downLoadFile&fileLogId=${backlFile.id}">${backlFile.oldFileName}</a>
                            </c:if>
                        </c:forEach>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </c:forEach>
    <c:if test="${not empty cbsBackEquipmentDetailEntities}">
</div>
</c:if>
<div class="subtitle">
    <p>日志</p>
    <table class="ftable">
        <tbody>
        <tr>
            <th>操作人</th>
            <th>时间</th>
            <th>描述</th>
        </tr>
        <c:forEach items="${cbsHandleLogEntities}" var="i">
            <tr>
                <td>${i.createName}</td>
                <td><fmt:formatDate value="${i.createDate}" type="date" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate></td>
                <td>${i.description}</td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>

</body>
<script>


    $(document).ready(function () {
        if($('#status').val()!=1){
           $('.contactsClass').css({
            'border':'white',
           })
            $('.contactsClass').attr("readonly","readonly")
        }
    })

    /*通知返件 id 返件主表id*/
    function notificationOfreturn(id) {
        $('.qhContacts').show()

        var flag=true;
        var rd_ = $("[id^=rd_]");  //返件明细id
        var rds = "";
        var logistics=$('#deliverLogistics').val()
        var name=$('#name').val()
        var phone=$('#phone').val()
        var address=$('#address').val()
        var sheng=$('#sheng').val()
        var shi=$('#shi').val()
        var cinemaName=$('#cinemaName').val()
        var datalist = new Array();
        rd_.each(function (i, item) {
            var object = new Object();
            var id=$("#rd_" + i).val();
            object.rd = $("#rd_" + i).val();
            object.typeDesc = $("#" + id).val();
            object.item = $("#" + id+"itemId").val();
            object.itemIn = $("#" + id+"in").val();
            object.returnEquipmentStatus = $("#returnEquipmentStatus_" + i).val();
            object.sn = $("#sn_" + i).val();
            object.photoName= $("#filedId" + i).text();
            object.equipmentErcode = $("#equipmentErcode_" + i).val();
            object.memo = $("#memo_" + i).val();
            datalist.push(object);


            if($("#" + id+"typeDes").val()==null || $("#" + id+"typeDes").val()==""){
                $("#"+id+"typeDesErr").show()
                parent.window.tip("请选择备件类型")
                flag=false;
                return false;
            }
            if($("#" + id+"in").val()==null || $("#" + id+"in").val()==""){
                $("#"+id+"itemIdErr").show()
                parent.window.tip("请填写备件号")
                flag=false;
                return false;
            }
            if($("#returnEquipmentStatus_" + i).val()==null || $("#returnEquipmentStatus_" + i).val()==""){
                $("#returnEquipmentStatus_"+i+"Err").show()
                parent.window.tip("请选择返件状态")
                flag=false;
                return false;
            }

            //判断是否序列号追踪
            if($("#" + id+"isTrack").val()=='is' && ($("#sn_" + i).val()==null || $("#sn_" + i).val()=="")){//是序列号追踪
                $("#sn"+id+"Err").show()
                parent.window.tip("请填写序列号")
                flag=false;
                return false;
            }
            if($("#" + id+"isTrack").val()=='is' && ($("#equipmentErcode_" + i).val()==null || $("#equipmentErcode_" + i).val()=="")){//是序列号追踪
                $("#equipmentErcode"+id+"Err").show()
                parent.window.tip("请填写二维码")
                flag=false;
                return false;
            }
            if($("#" + id+"isTrack").val()=='is' && ($("#fileId_" + i).text().trim()==null || $("#fileId_" + i).text().trim()=='')){//是序列号追踪
                $("#photo"+i+"Err").show()
                parent.window.tip("请上传备件照片")
                flag=false;
                return false;
            }
        });

        if($('#name').val()==null || $('#name').val()==''){
            $("#nameErr").show()
            parent.window.tip("请填写取货联系人姓名")
            flag=false;
            return false;
        }
        if($('#phone').val()==null || $('#phone').val()==''){
            $("#phoneErr").show()
            parent.window.tip("请填写取货联系人电话")
            flag=false;
            return false;
        }
        if($('#sheng').val()==null || $('#sheng').val()==''){
            $("#shiErr").show()
            parent.window.tip("请选择省市")
            flag=false;
            return false;
        }
        if($('#shi').val()==null || $('#shi').val()==''){
            $("#shiErr").show()
            parent.window.tip("请选择省市")
            flag=false;
            return false;
        }
        if($('#address').val()==null || $('#address').val()==''){
            $("#addressErr").show()
            parent.window.tip("请填写取货地址")
            flag=false;
            return false;
        }
        console.info("返件明细datalist==" + datalist);
        if(flag){
            if (rd_ == '' || rd_ == null) {
                tip("没有要返件的信息，请核对后再返件！");
            } else {
                $.ajax({
                    url: "cbsReturnEquipmentController.do?doReturnEquipment",
                    data: {"datalist": JSON.stringify(datalist),"id":id,"logistics":logistics,"name":name,"phone":phone,"address":address,"cinemaName":cinemaName
                    ,"sheng":sheng,"shi":shi},
                    cache: false,
                    dataType: 'json',
                    type: 'POST',
                    success: function (data) {
                        tip(data.msg);
                        if(data.success){
                            var Recode = $("#reTurnCode").text();
                            var tabName =  "返件详情"+Recode;
                            setTimeout("addOneTab('返件管理','cbsReturnEquipmentController.do?cbsReturnEquipmentCSA');",1000);
                            setTimeout("closetab('"+tabName+"')",1000);
                        }
                    }
                });
            }
        }

    }

    /**
     * 取消返件
     * @param id 主表id
     */
    function cancelTheShipment(id) {
        var status = $("#status").val();
        if(status==1 ||status==2 ||status==3){
            $.dialog({
                content: 'url:cbsDelinerController.do?goCancelTheShipment&id='+id,
                lock: true,
                width: 500,
                height: 250,
                title: '取消',
                opacity: 0.3,
                cache: false,
                ok: function () {
                    iframe = this.iframe.contentWindow;
                    iframe.$('#formobj').submit();

                    return false;
                },
                cancelVal: '关闭',
                cancel: true /*为true等价于function(){}*/
            }).zindex();
        }else{
            tip("不能取消返件！");
        }
    }

    /**
     * 保存物流 id = 主表id
     * */
    function preservation(id){
        var flag=true;
        var rd_ = $("[id^=rd_]");  //返件明细id
        var rds = "";
        var logistics=$('#deliverLogistics').val()
        var name=$('#name').val()
        var phone=$('#phone').val()
        var address=$('#address').val()
        var sheng=$('#sheng').val()
        var shi=$('#shi').val()
        var cinemaName=$('#cinemaName').val()
        var datalist = new Array();
        rd_.each(function (i, item) {
            var object = new Object();
            var id=$("#rd_" + i).val();
            object.rd = $("#rd_" + i).val();
            object.typeDesc = $("#" + id).val();
            object.item = $("#" + id+"itemId").val();
            object.itemIn = $("#" + id+"in").val();
            object.returnEquipmentStatus = $("#returnEquipmentStatus_" + i).val();
            object.sn = $("#sn_" + i).val();
            object.photoName= $("#filedId" + i).text();
            object.equipmentErcode = $("#equipmentErcode_" + i).val();
            object.memo = $("#memo_" + i).val();
            datalist.push(object);

        });
        console.info("返件明细datalist==" + datalist);
        if(flag){
            if (rd_ == '' || rd_ == null) {
                tip("没有要返件的信息，请核对后再返件！");
            } else {
                $.ajax({
                    url: "cbsReturnEquipmentController.do?dopreservation",
                    data: {"datalist": JSON.stringify(datalist),"id":id,"logistics":logistics,"name":name,"phone":phone,"address":address,"cinemaName":cinemaName
                    ,"sheng":sheng,"shi":shi},
                    cache: false,
                    dataType: 'json',
                    type: 'POST',
                    success: function (data) {
                        var Recode = $("#reTurnCode").text();
                        var tabName =  "返件详情"+Recode;
                        setTimeout("addOneTab('返件管理','cbsReturnEquipmentController.do?cbsReturnEquipmentCSA');",1000);
                        setTimeout("closetab('"+tabName+"')",1000);
                        tip(data.msg);
                    }
                });


            }
        }
    }

    /*
        * 根据返件物流获取联系人
        * */
    function getContacts(){

        var logisticsName = $("#deliverLogistics").val();
        $.ajax({
            type:"GET",
            data:{"code":logisticsName},
            url:"cbsDelinerController.do?getContacts",
            dataType:"json",
            success:function (data) {
                var tbs = data.obj;
                if(tbs==null || tbs==""){
                    $("#userName").text("暂无信息");
                    $("#cellphone1").text("暂无信息");
                    $("#email").text("暂无信息");
                }else{
                    $("#userName").text(tbs.name);
                    $("#cellphone1").text(tbs.cellphone1);
                    $("#email").text(tbs.email);
                }
            }
        });
    }


    function getTree(obj,id){
        $('.'+id+'isTrack').hide()
        var uuid=obj.id;
        //alert("uuid:"+uuid)
        $.dialog({
            content: "url:cbsDelinerController.do?goChooseEquipmentType&uuid="+uuid+"&id="+id,
            zIndex: 2100,
            title: '机型',
            lock: true,
            width: '300px',
            height: '400px',
            left: '55%',
            top: '65%',
            opacity: 0.4,
            init: function () {
                top.myWindow = window;
            },
        });
    }


    function getIsTrack(id) {
        var itemId=$('#'+id+'itemId').val()
        $.ajax({
            url: "cbsReturnEquipmentController.do?getItmById",
            data: {"id": itemId},
            cache: false,
            dataType: 'json',
            type: 'POST',
            success: function (data) {
                var item=data.obj
                if(item.isTrack=='1'){
                    $('#'+id+'isTrack').val('is')
                    $('.'+id+'isTrack').show()
                }else{
                    $('#'+id+'isTrack').val('')
                    $('.'+id+'isTrack').hide()
                    $("#equipmentErcode"+id+"Err").hide()
                    $("#sn"+id+"Err").hide()
                }
            }
        });
    }
    function checkeNull(obj) {
        //alert("id:"+obj.id)
        //alert("value:"+obj.value)
        var value=obj.value;
        if(value==null || value=='' || value=='0'){
            $('#'+obj.id+'Err').show();
        }else {
            $('#'+obj.id+'Err').hide();
        }
    }
    function hideErr(type,obj) {
        // alert("type:"+type)
        var value=obj.value;
        // alert("value:"+obj.value)
        if(value!=null && value!=''){
            $('#'+type+'Err').hide()

        }
        //alert("value:"+obj.value)
    }



    $(function () {
        var rd_ = $("[id^=rd_]");  //返件明细id
        var returnId=$('#returnId').val()
        rd_.each(function (i, item) {
            var rd = '#rd_' + i;
            var photoName = '#photoNames_' + i;
            var id = $(rd).val();

            $(photoName).uploadify({
                buttonText: '上传文件',
                auto: true,
                progressData: 'speed',
                multi: true,
                height: 20,
                width: 60,
                overrideEvents: ['onDialogClose'],
                fileTypeDesc: '文件格式:',
                queueID: 'instructionfile',
                fileTypeDesc : '文件格式:',
                fileTypeExts : '*', //控制可上传文件的扩展名，启用本项时需同时声明fileDesc
                fileSizeLimit : '50MB',
                swf: 'plug-in/uploadify/uploadify.swf',
                uploader: 'fileUploadController.do?uploadFileReturn&businessKey='+returnId+'&sessionId=' + $("#sessionId").val()+'&childKey='+id,
                onUploadStart:function(){
                    lockmask(true,'请稍等,导入中...');
                },
                onUploadSuccess: function (file, data) {
                    lockmask(false);
                    var fileBean = $.parseJSON(data).attributes;
                    var html = '<span name="fileIda" id="filedId'+i+'">' +
                        '<span class="color-blue" id="' + fileBean.fileKey + '" >' + fileBean.name + '</span>&nbsp;&nbsp; ' +
                        '<span style="cursor: pointer;" onclick=\'delFile("' + fileBean.fileKey + '","' + i + '")\'>删除</span>&emsp;' +
                        '</span>';
                    $("#fileId_" + i).prepend(html);
                    //$("#photoName_" + i).val(fileBean.fileKey);
                    $("#photo"+i+"Err").hide()
                    tip("上传成功！");
                }, onFallback: function () {
                    tip("您未安装FLASH控件，无法上传文件！请安装FLASH控件后再试");
                }, onSelectError: function (file, errorCode, errorMsg) {
                    switch (errorCode) {
                        case -100:
                            tip("上传的文件数量已经超出系统限制的" + $('#instruction').uploadify('settings', 'queueSizeLimit') + "个文件！");
                            break;
                        case -110:
                            tip("文件 [" + file.name + "] 大小超出系统限制的50MB大小！");break;
                        case -120:
                            tip("文件 [" + file.name + "] 大小异常！");
                            break;
                        case -130:
                            tip("文件 [" + file.name + "] 类型不正确！");
                            break;
                    }
                }
            });

        });

    });

    function delFile(id,i){
        $.ajax({
            url : "fileUploadController.do?delFileReturn",
            data : {
                "id" : id
            },
            cache : false,
            dataType : 'json',
            type : 'POST',
            async : false,
            success : function(data){
                if(!data.success){
                    tip(data.msg);
                    return false;
                }else{
                    $("#filedId"+i).remove();
                    $("#photoName_"+i).hide();
                    tip("删除成功！");
                }
            }
        });
    }

    function getItem(id) {
        var itemValue=$('#'+id+'itemId').val()
        $('#'+id+'in').val(itemValue)
    }
</script>
</html>
